package com.client.elements.normal.boxes;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

public class Aufklappbox {
	private static boolean open = true; 

	final static FlowPanel panel = new FlowPanel();
	final static HorizontalPanel header_panel = new HorizontalPanel();
	final static Button neu = new Button();
	final static FlowPanel body_panel = new FlowPanel();
	
	public static Widget aufklappbox(){
		panel.clear();
		header_panel.clear();
		body_panel.clear();
		panel.addStyleName("master");
		Label label = new Label("Header");
		label.setWidth("5px");
		header_panel.add(label);
		header_panel.addStyleName("header");
		panel.add(header_panel);

		neu.setStyleName("btn_close");
		header_panel.add(neu);
		header_panel.setCellHorizontalAlignment(neu, HasHorizontalAlignment.ALIGN_RIGHT);

		body_panel.add(new HTML("Test1<br>Test2"));
		panel.add(body_panel);

		neu.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				aufzuklappen();
			}
		});
		
		return panel;
	}
	
	private static void aufzuklappen(){
		open = !open;
		body_panel.setVisible(open);
		if (!open) {
			panel.removeStyleName("master");
			neu.setStyleName("btn_open");
			header_panel.addStyleName("border");
		}else {
			panel.addStyleName("master");
			neu.setStyleName("btn_close");
			header_panel.removeStyleName("border");
		}
	}
}